#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
 
int main (void) 
{
    int n, fd;
    char read_buf[125]={};
    char *p =NULL;
    char write_buff[125]="test_cse_ssg";
    char write_buff_2[125]="wdcr";
    printf("\n0:this is read_buf:read_buf = %s\n",read_buf);
 
    fd = open ("/dev/hello", O_RDWR);
    if (fd < 0) {
        perror("open");
        exit(0);
    }
    printf ("\n/dev/hello opened, fd=%d!\n", fd);
 
  
    /* write */
    printf("1:Write buffer: %s\n", write_buff);
    int ret_write=(int)write (fd, write_buff, strlen(write_buff));
    if (ret_write < 0)
    {
        perror("fail to write");
    }
    else printf ("Write returns %d bytes\n",ret_write);
    
    printf("\n2:Write buffer: %s\n", write_buff_2);
    ret_write=(int)write (fd, write_buff_2, strlen(write_buff_2));
    if (ret_write < 0)
    {
        perror("fail to write");
    }
    else printf ("Write returns %d bytes\n",ret_write);
 
 
    /* read */
    for(int i=1;i<=8;i++)
    {
    	printf ("\nRead returns %d bytes", (int)read (fd, read_buf,2));
    	printf("\n%d:this is read_buf:read_buf = %s\n",i,read_buf);
   	//printf("read_buf = %s\n", read_buf);
    }
 
 
    close (fd);
    printf ("/dev/hello closed!\n");
    return 0;
 
}
